<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="股票代码" prop="symbol">
      <el-input v-model="dataForm.symbol" placeholder="股票代码"></el-input>
    </el-form-item>
    <el-form-item label="股票名称" prop="stockChiName">
      <el-input v-model="dataForm.stockChiName" placeholder="股票名称"></el-input>
    </el-form-item>
    <el-form-item label="连板" prop="limitUpDays">
      <el-input v-model="dataForm.limitUpDays" placeholder="连板"></el-input>
    </el-form-item>
    <el-form-item label="原因或概念" prop="concept">
      <el-input v-model="dataForm.concept" placeholder="原因或概念"></el-input>
    </el-form-item>
    <el-form-item label="涨停分析" prop="surgeReason">
      <el-input v-model="dataForm.surgeReason" placeholder="涨停分析"></el-input>
    </el-form-item>
    <el-form-item label="涨停价" prop="price">
      <el-input v-model="dataForm.price" placeholder="涨停价"></el-input>
    </el-form-item>
    <el-form-item label="封单比" prop="buyLockVolumeRatio">
      <el-input v-model="dataForm.buyLockVolumeRatio" placeholder="封单比"></el-input>
    </el-form-item>
    <el-form-item label="换手率" prop="exchangeRatio">
      <el-input v-model="dataForm.exchangeRatio" placeholder="换手率"></el-input>
    </el-form-item>
    <el-form-item label="流通市值" prop="circulationMarketValue">
      <el-input v-model="dataForm.circulationMarketValue" placeholder="流通市值"></el-input>
    </el-form-item>
    <el-form-item label="总市值" prop="totalValue">
      <el-input v-model="dataForm.totalValue" placeholder="总市值"></el-input>
    </el-form-item>
    <el-form-item label="首封时间" prop="firstLimitUp">
      <el-input v-model="dataForm.firstLimitUp" placeholder="首封时间"></el-input>
    </el-form-item>
    <el-form-item label="封住时间" prop="lastLimitUp">
      <el-input v-model="dataForm.lastLimitUp" placeholder="封住时间"></el-input>
    </el-form-item>
    <el-form-item label="开板次数" prop="breakLimitUpTimes">
      <el-input v-model="dataForm.breakLimitUpTimes" placeholder="开板次数"></el-input>
    </el-form-item>
    <el-form-item label="几天几板" prop="continuation">
      <el-input v-model="dataForm.continuation" placeholder="几天几板"></el-input>
    </el-form-item>
    <el-form-item label="" prop="date">
      <el-input v-model="dataForm.date" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          symbol: '',
          stockChiName: '',
          limitUpDays: '',
          concept: '',
          surgeReason: '',
          price: '',
          buyLockVolumeRatio: '',
          exchangeRatio: '',
          circulationMarketValue: '',
          totalValue: '',
          firstLimitUp: '',
          lastLimitUp: '',
          breakLimitUpTimes: '',
          continuation: '',
          date: ''
        },
        dataRule: {
          symbol: [
            { required: true, message: '股票代码不能为空', trigger: 'blur' }
          ],
          stockChiName: [
            { required: true, message: '股票名称不能为空', trigger: 'blur' }
          ],
          limitUpDays: [
            { required: true, message: '连板不能为空', trigger: 'blur' }
          ],
          concept: [
            { required: true, message: '原因或概念不能为空', trigger: 'blur' }
          ],
          surgeReason: [
            { required: true, message: '涨停分析不能为空', trigger: 'blur' }
          ],
          price: [
            { required: true, message: '涨停价不能为空', trigger: 'blur' }
          ],
          buyLockVolumeRatio: [
            { required: true, message: '封单比不能为空', trigger: 'blur' }
          ],
          exchangeRatio: [
            { required: true, message: '换手率不能为空', trigger: 'blur' }
          ],
          circulationMarketValue: [
            { required: true, message: '流通市值不能为空', trigger: 'blur' }
          ],
          totalValue: [
            { required: true, message: '总市值不能为空', trigger: 'blur' }
          ],
          firstLimitUp: [
            { required: true, message: '首封时间不能为空', trigger: 'blur' }
          ],
          lastLimitUp: [
            { required: true, message: '封住时间不能为空', trigger: 'blur' }
          ],
          breakLimitUpTimes: [
            { required: true, message: '开板次数不能为空', trigger: 'blur' }
          ],
          continuation: [
            { required: true, message: '几天几板不能为空', trigger: 'blur' }
          ],
          date: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/stocklimitup/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.symbol = data.stockLimitUp.symbol
                this.dataForm.stockChiName = data.stockLimitUp.stockChiName
                this.dataForm.limitUpDays = data.stockLimitUp.limitUpDays
                this.dataForm.concept = data.stockLimitUp.concept
                this.dataForm.surgeReason = data.stockLimitUp.surgeReason
                this.dataForm.price = data.stockLimitUp.price
                this.dataForm.buyLockVolumeRatio = data.stockLimitUp.buyLockVolumeRatio
                this.dataForm.exchangeRatio = data.stockLimitUp.exchangeRatio
                this.dataForm.circulationMarketValue = data.stockLimitUp.circulationMarketValue
                this.dataForm.totalValue = data.stockLimitUp.totalValue
                this.dataForm.firstLimitUp = data.stockLimitUp.firstLimitUp
                this.dataForm.lastLimitUp = data.stockLimitUp.lastLimitUp
                this.dataForm.breakLimitUpTimes = data.stockLimitUp.breakLimitUpTimes
                this.dataForm.continuation = data.stockLimitUp.continuation
                this.dataForm.date = data.stockLimitUp.date
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/stocklimitup/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'symbol': this.dataForm.symbol,
                'stockChiName': this.dataForm.stockChiName,
                'limitUpDays': this.dataForm.limitUpDays,
                'concept': this.dataForm.concept,
                'surgeReason': this.dataForm.surgeReason,
                'price': this.dataForm.price,
                'buyLockVolumeRatio': this.dataForm.buyLockVolumeRatio,
                'exchangeRatio': this.dataForm.exchangeRatio,
                'circulationMarketValue': this.dataForm.circulationMarketValue,
                'totalValue': this.dataForm.totalValue,
                'firstLimitUp': this.dataForm.firstLimitUp,
                'lastLimitUp': this.dataForm.lastLimitUp,
                'breakLimitUpTimes': this.dataForm.breakLimitUpTimes,
                'continuation': this.dataForm.continuation,
                'date': this.dataForm.date
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
